package com.huiquan.management.dao;

import com.huiquan.analysis.constants.AnalysisSentenceConstant;
import com.huiquan.analysis.dao.BaseDao;
import com.huiquan.framework.utils.StringUpperUtil;
import com.huiquan.management.constant.MigrateCode;
import com.ibatis.sqlmap.client.SqlMapClient;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class MigrateSwitchDao extends BaseDao {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "MIGRATE_SWITCH.";

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveMigrateData(MigrateCode mc) {

		String mcName = mc.name();

		Map<String, Object> param = new HashMap<>();
		// 现病史获取数据需加参数 
		if (mcName.startsWith("XBS_NEW_TRAIN_BME")) {
			String migrateNameSub = mcName.substring("XBS_NEW_TRAIN_BME_".length());
			for (String key : AnalysisSentenceConstant.XBS_SOURCE_TYPE_SIMPLE_TITLE.keySet()) {
				String keyUpperCase = StringUpperUtil.changeStr(key);
				if (keyUpperCase.equals(migrateNameSub)) {
					param.put("secondType", key);
					break;
				}
			}
			if(mcName.indexOf("IMAGEOLOGY_INFO") < 0) {
				mcName = "XBS_NEW_TRAIN_BME";
			}
		} else 	if (mcName.startsWith("XBS_NEW_TRAIN")) {
			String migrateNameSub = mcName.substring("XBS_NEW_TRAIN_".length());
			for (String key : AnalysisSentenceConstant.XBS_SOURCE_TYPE_SIMPLE_TITLE.keySet()) {
				String keyUpperCase = StringUpperUtil.changeStr(key);
				if (keyUpperCase.equals(migrateNameSub)) {
					param.put("secondType", key);
					break;
				}
			}
			if(mcName.indexOf("IMAGEOLOGY_INFO") < 0) {
				mcName = "XBS_NEW_TRAIN";
			}
		} else if(mcName.startsWith("XBS_SUB_SENTENCE")) {
			for (String key : AnalysisSentenceConstant.XBS_SOURCE_TYPE_SIMPLE_TITLE.keySet()) {
				String keyUpperCase = StringUpperUtil.changeStr(key);
				String migrateNameSub = mcName.substring("XBS_SUB_SENTENCE_".length());
				if (keyUpperCase.equals(migrateNameSub)) {
					param.put("secondType", key);
					break;
				}
			}
			mcName = "XBS_SUB_SENTENCE";
		}

		return (List<Map<String, Object>>) this.list(space + "RETRIEVE_" + mcName, param, sqlMapClient);
	}
}
